package model.areas;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class HistorialAreaDocente {
	
	private static HistorialAreaDocente instance;
	private List<AreaEnHistorial> areasHistorial;
	
	private HistorialAreaDocente(){
		super();
		this.areasHistorial = new ArrayList<AreaEnHistorial>();
	}
	
	public static HistorialAreaDocente getInstance(){
		if(instance == null){
			instance = new HistorialAreaDocente();
		}
		return instance;
	}
	
	public void agregarAreaEnHistorial(AreaEnHistorial area){
		this.areasHistorial.add(area);
	}
	
	public void cerrarUltimoHistorial(Area area) {
		List<AreaEnHistorial> list = this.getAllHistorialDeArea(area);
		if(list.lastIndexOf(area) != -1){
			AreaEnHistorial areaEnHistorial = list.get(list.lastIndexOf(area));
			areaEnHistorial.setFechaFin(new Date());
		}
	}
	
	public List<AreaEnHistorial> getAllHistorialDeArea(Area area){
		List<AreaEnHistorial> areas = new ArrayList<AreaEnHistorial>();
		for (AreaEnHistorial areaEnHistorial : this.areasHistorial) {
			if(areaEnHistorial.getArea().getNombre() == area.getNombre()){
				areas.add(areaEnHistorial);
			}
		}
		return areas;
	}
	
	public List<AreaEnHistorial> getAreasHistorial() {
		return areasHistorial;
	}

	public void setAreasHistorial(List<AreaEnHistorial> areasHistorial) {
		this.areasHistorial = areasHistorial;
	}

	
}
